import request from '@/utils/request'
import type { SpuSaleAttrData } from './spu'

export interface SkuImageData {
  id: number
  skuId: number | undefined
  imgName: string
  imgUrl: string
  spuImgId: number
  isDefault: string
}

export interface SkuAttrValueData {
  id?: number
  attrId: number | string
  valueId: number | string
  skuId?: number
  attrName?: string
  valueName?: string
}

export interface SkuSaleAttrValueData {
  id?: number
  skuId?: number
  spuId?: number
  saleAttrValueId: number | string
  saleAttrId: number | string
  saleAttrName?: string
  saleAttrValueName?: string
}

export type SkuData = {
  id?: number
  spuId: number | string
  price: number | string
  skuName: string
  skuDesc: string
  weight: string
  tmId: number | string
  category3Id: number | string
  skuDefaultImg: string
  isSale?: number
  createTime?: string
  skuImageList: SkuImageData[]
  skuAttrValueList: SkuAttrValueData[]
  skuSaleAttrValueList: SkuSaleAttrValueData[]
}

type SkuPageListData = {
  records: SkuData[]
  total: number
  size: number
  current: number
  searchCount: boolean
  pages: number
}

export interface SpuImageData {
  id?: number
  spuId?: number
  imgName: string
  imgUrl: string
  name?: string
  url?: string
  response?: any
  isDefault?: string
}
export default {
  // 下架商品
  // GET /admin/product/cancelSale/{skuId}
  // cancelSale
  cancelSale(skuId: number) {
    return request.get<any, null>(`/admin/product/cancelSale/${skuId}`)
  },

  // 上架商品
  // GET /admin/product/onSale/{skuId}
  // onSale
  onSale(skuId: number) {
    return request.get<any, null>(`/admin/product/onSale/${skuId}`)
  },

  // DELETE /admin/product/deleteSku/{skuId}
  // deleteSku
  deleteSku(skuId: number) {
    return request.delete<any, null>(`/admin/product/deleteSku/${skuId}`)
  },

  // 根据spu的id获取sku的列表
  // GET /admin/product/findBySpuId/{spuId}
  // findBySpuId
  findBySpuId(spuId: number) {
    return request.get<any, SkuData[]>(`/admin/product/findBySpuId/${spuId}`)
  },
  // 根据sku的id获取sku详情
  // GET /admin/product/getSkuById/{skuId}
  // getById
  getById(skuId: number) {
    return request.get<any, SkuData>(`/admin/product/getSkuById/${skuId}`)
  },

  // GET /admin/product/inner/findSkuInfoByKeyword/{keyword}
  // findSkuInfoByKeyword 不用

  // POST /admin/product/inner/findSkuInfoBySkuIdList
  // findSkuInfoBySkuIdList 不用

  // GET /admin/product/list/{page}/{limit}
  // index
  getPageList(page: number, limit: number) {
    return request.get<any, SkuPageListData>(
      `/admin/product/list/${page}/${limit}`
    )
  },

  // POST /admin/product/saveSkuInfo
  // saveSkuInfo
  saveSkuInfo(sku: SkuData) {
    return request.post<any, null>('/admin/product/saveSkuInfo', sku)
  },

  // 根据spu的id获取spu图片列表
  // GET /admin/product/spuImageList/{spuId}
  // getSpuImageList
  getSpuImageList(spuId: number) {
    return request.get<any, SpuImageData[]>(
      `/admin/product/spuImageList/${spuId}`
    )
  },

  // 根据spu的id获取spu自己的销售属性列表
  // GET /admin/product/spuSaleAttrList/{spuId}
  // getSpuSaleAttrList
  getSpuSaleAttrList(spuId: number) {
    return request.get<any, SpuSaleAttrData[]>(
      `/admin/product/spuSaleAttrList/${spuId}`
    )
  },

  // POST /admin/product/updateSkuInfo
  // updateSkuInfo   不用
}
